package com.sangmo.fts.process.receivable.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "rpf_pledge_contract")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class RpfPledgeContract extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50, index = true, unique = true)
    private String code;

    @One(value = "waybill", target = RpfWaybill.class, fieldset = {"id","code"}, groups = {"RpfPledgeContract.search","RpfPledgeContract.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long waybillId;

    @One(value = "contract", target = RpfContract.class, fieldset = {"id","code"}, groups = {"RpfPledgeContract.search","RpfPledgeContract.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long contractId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long loanId;

    @One(value = "pledgorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long pledgor;

    @One(value = "pledgeeCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long pledgee;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal receivableAmount;

    @One(value = "subDebtorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long subDebtor;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date dueDate;

    @One(value = "pledgorConfirmDocument", target = FileUpload.class, groups = {"RpfPledgeContract.search","RpfPledgeContract.detail"}, fieldset = {"id","url","fileName"})
    private Long pledgorConfirmDoc;

    @One(value = "pledgeeConfirmDocument", target = FileUpload.class, groups = {"RpfPledgeContract.search","RpfPledgeContract.detail"}, fieldset = {"id","url","fileName"})
    private Long pledgeeConfirmDoc;

    @One(value = "buyerConfirmDocument", target = FileUpload.class, groups = {"RpfPledgeContract.search","RpfPledgeContract.detail"}, fieldset = {"id","url","fileName"})
    private Long buyerConfirmDoc;

    @DataField(index = true)
    private boolean pledgorConfirm;

    @DataField(index = true)
    private boolean pledgeeConfirm;

    private boolean registered;

    @DataField(index = true)
    private boolean notified;

    private boolean buyerConfirm;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getWaybillId() {
        return waybillId;
    }

    public void setWaybillId(Long waybillId) {
        this.waybillId = waybillId;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getPledgor() {
        return pledgor;
    }

    public void setPledgor(Long pledgor) {
        this.pledgor = pledgor;
    }

    public Long getPledgee() {
        return pledgee;
    }

    public void setPledgee(Long pledgee) {
        this.pledgee = pledgee;
    }

    public BigDecimal getReceivableAmount() {
        return receivableAmount;
    }

    public void setReceivableAmount(BigDecimal receivableAmount) {
        this.receivableAmount = receivableAmount;
    }

    public Long getSubDebtor() {
        return subDebtor;
    }

    public void setSubDebtor(Long subDebtor) {
        this.subDebtor = subDebtor;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public Long getPledgorConfirmDoc() {
        return pledgorConfirmDoc;
    }

    public void setPledgorConfirmDoc(Long pledgorConfirmDoc) {
        this.pledgorConfirmDoc = pledgorConfirmDoc;
    }

    public Long getPledgeeConfirmDoc() {
        return pledgeeConfirmDoc;
    }

    public void setPledgeeConfirmDoc(Long pledgeeConfirmDoc) {
        this.pledgeeConfirmDoc = pledgeeConfirmDoc;
    }

    public Long getBuyerConfirmDoc() {
        return buyerConfirmDoc;
    }

    public void setBuyerConfirmDoc(Long buyerConfirmDoc) {
        this.buyerConfirmDoc = buyerConfirmDoc;
    }

    public boolean isPledgorConfirm() {
        return pledgorConfirm;
    }

    public void setPledgorConfirm(boolean pledgorConfirm) {
        this.pledgorConfirm = pledgorConfirm;
    }

    public boolean isPledgeeConfirm() {
        return pledgeeConfirm;
    }

    public void setPledgeeConfirm(boolean pledgeeConfirm) {
        this.pledgeeConfirm = pledgeeConfirm;
    }

    public boolean isRegistered() {
        return registered;
    }

    public void setRegistered(boolean registered) {
        this.registered = registered;
    }

    public boolean isNotified() {
        return notified;
    }

    public void setNotified(boolean notified) {
        this.notified = notified;
    }

    public boolean isBuyerConfirm() {
        return buyerConfirm;
    }

    public void setBuyerConfirm(boolean buyerConfirm) {
        this.buyerConfirm = buyerConfirm;
    }
}
